package com.zlzxm.shoesmarket.view.adapter;

import android.graphics.Color;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.zlzxm.shoesmarket.R;
import com.zlzxm.shoesmarket.view.adapter.entity.EntityOperateSize;

import org.jetbrains.annotations.NotNull;

/**
 * CREATE BY zlzxm ON 4/20/21
 */
public class ADGoodsSizeOperate extends BaseQuickAdapter<EntityOperateSize,
        BaseViewHolder> {
    public ADGoodsSizeOperate() {
        super(R.layout.item_goods_size_save);
        addChildClickViewIds(R.id.ivSub,R.id.ivAdd);
    }

    @Override
    protected void convert(@NotNull BaseViewHolder baseViewHolder, EntityOperateSize entity) {

        baseViewHolder.setText(R.id.tvSize,entity.getSize());
        baseViewHolder.setText(R.id.tvPrice,entity.getPrice());
        baseViewHolder.setText(R.id.tvNum,entity.getNum()+"");
        baseViewHolder.setText(R.id.tvNote,entity.getNote());

        if(baseViewHolder.getBindingAdapterPosition() == getData().size()-1){

            baseViewHolder.itemView.setBackgroundResource(R.drawable.item_bottom_corner);

        }else {

            baseViewHolder.itemView.setBackgroundResource(0);
            baseViewHolder.itemView.setBackgroundColor(Color.WHITE);

        }

        EditText editText = baseViewHolder.getView(R.id.tvPrice);
        editText.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                entity.setPrice(s.toString());
            }
        });
    }

}
